package com.baselibrary.bean.download

import java.text.DecimalFormat


object ShowUIUtils {
    //数量大于99 显示99
    fun showFormatCnt(cnt: Int): String {
        return if (cnt > 99) "99" else "${cnt}"
    }

    private val df = DecimalFormat("#.#")
    @JvmStatic
    fun byteToString(b: Double): String {
        var b = b
        if (b < 1024) {
            return df.format(b) + "B"
        }

        b /= 1024.0

        if (b < 1024) {
            return df.format(b) + "KB"
        }

        b /= 1024.0

        if (b < 1024) {
            return df.format(b) + "MB"
        }

        b /= 1024.0

        if (b < 1024) {
            return df.format(b) + "GB"
        }

        b /= 1024.0

        return df.format(b) + "TB"
    }
}